<?php

use yii\helpers\Html;
use yii\grid\GridView;
use app\models\Role;
use yii\helpers\ArrayHelper;

/* @var $this yii\web\View */
/* @var $searchModel app\models\AdminSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '用户信息列表';
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="admin-index">
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>

    <p>
        <?= Html::a('添加用户', ['create'], ['class' => 'btn btn-success']) ?>
    </p>
    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            ['class' => 'yii\grid\SerialColumn'],

            'id',
            'adm_username',
            'adm_password',
            [
                'label' => '角色名称', // 可选 复写
                'attribute' => 'role_id',
                'filter' => Html::activeDropDownList($searchModel, 'role_id', ArrayHelper::map(Role::find()->all(),'id','role_name'), ['class' => 'form-control']),
                'value' => function ($data) {
                //return $data->role_id;
                    $role = new Role;
                    return $role->getRolename($data->role_id);
                },
            ],
           

            ['class' => 'yii\grid\ActionColumn'],
        ],
    ]); ?>
</div>
